package com.gitee.luosl.cola.lang.function.checked;

import com.gitee.luosl.cola.util.Try;

import java.util.function.Function;

@FunctionalInterface
public interface CheckedFunction<T, R> {

    R apply(T t) throws Throwable;

    default Function<T, R> toFunction() {
        return t -> {
            try{
                return apply(t);
            }catch (Throwable throwable){
                throw new CheckedException(throwable);
            }
        };
    }

    default Function<T, Try<R>> lift() {
        return t -> Try.of(() -> apply(t));
    }
}
